home *** CD-ROM | disk | FTP | other *** search
/ ftp.cs.arizona.edu / ftp.cs.arizona.edu.tar / ftp.cs.arizona.edu / icon / newsgrp / group99a.txt / 000097_icon-group-sender _Fri Apr 9 13:03:04 1999.msg < prev    next >
Internet Message Format  |  2000-09-20  |  2KB

  1. Return-Path: <icon-group-sender>
  2. Received: (from root@localhost)
  3.     by baskerville.CS.Arizona.EDU (8.9.1a/8.9.1) id NAA23393
  4.     for icon-group-addresses; Fri, 9 Apr 1999 13:01:54 -0700 (MST)
  5. Message-Id: <199904092001.NAA23393@baskerville.CS.Arizona.EDU>
  6. From: "Nevin Liber" <nevin@eviloverlord.com>
  7. To: <icon-group@optima.CS.Arizona.EDU>
  8. Cc: "Hudon, Christian (EXCHANGE:MTL:6X16)" <chudon@americasm01.nt.com>
  9. Subject: RE: Deep copy in Icon?
  10. Date: Fri, 9 Apr 1999 10:33:54 -0500
  11. X-Priority: 3 (Normal)
  12. X-MSMail-Priority: Normal
  13. Importance: Normal
  14. X-MimeOLE: Produced By Microsoft MimeOLE V5.00.2014.211
  15. Errors-To: icon-group-errors@optima.CS.Arizona.EDU
  16. Status: RO
  17.  
  18. > procedure deepcopy(x, t)
  19. >     /t := table()
  20. >     case type(x) of {
  21. >         "list"|"table"|"set"|"record" : {
  22. >             e := t[image(x)]
  23. >             if /e then {
  24. >                 e := copy(x)
  25. >                 t[image(x)] := e
  26. >                 every sub := !e do sub := deepcopy(sub, t)
  27. >                 }
  28. >         return e
  29. >         }
  30. >        default: return x
  31. >     }
  32. > end
  33.  
  34. > (This is supposed to do a deep copy of an arbitrary object, preserving
  35. > the structure.)
  36.  
  37. First off, good job on dealing with the problems of self-referential data
  38. structures, such as
  39.  
  40.     L := list()
  41.     put(L, L)
  42.  
  43. although you can just use x instead of image(x) in your above snippet and it
  44. will still work.
  45.  
  46. > I thought you could assign to the elements of a set, list, etc. with
  47. > something like
  48.  
  49. >   every e := !l do e := foo(e)
  50.  
  51. What you need is something like:
  52.  
  53.     every i := 1 to *l do l[i] := foo(l[i])
  54.  
  55. To borrow from C++ terminology, the difference is that l[i] is a "reference"
  56. (l-value) to element i in list l, while e is the "value" of element i in
  57. list l.
  58. __
  59.  Nevin ":-)" Liber  <mailto:nevin@eviloverlord.com>  (312) 855-1000 x199
  60.  
  61.